package com.ngovanhau.justsort.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.ngovanhau.justsort.R;
import com.ngovanhau.justsort.model.Level;

public class TitleNoRow implements Row{
	private final Level level;
	private final LayoutInflater inflater;

	public TitleNoRow(LayoutInflater inflater, Level level) {
		this.level = level;
		this.inflater = inflater;
	}

	public View getView(View convertView, ViewGroup group) {
		ViewHolder holder;
		View view;
		// we have a don't have a converView so we'll have to create a new one
		if (convertView == null) {
			ViewGroup viewGroup = (ViewGroup) inflater.inflate(
					R.layout.listview_item_level_no, group, false);

			// use the view holder pattern to save of already looked up subviews
			holder = new ViewHolder((TextView) viewGroup.findViewById(R.id.lv_title_no));
			viewGroup.setTag(holder);

			view = viewGroup;
		} else {
			// get the holder back out
			holder = (ViewHolder) convertView.getTag();

			view = convertView;
		}

		// actually setup the view
		if(level.getLevel() <=5){
			holder.titleView.setText("Level "+level.getLevel());
		}else{
			holder.titleView.setText("Extra Level");
		}
		
		return view;
	}

	public int getViewType() {
		return RowType.TITLE_NO.ordinal();
	}

	private static class ViewHolder {
		final TextView titleView;

		private ViewHolder(TextView titleView) {
			this.titleView = titleView;
		}
	}
}
